﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

using XGameFrame;
using XGameFrame.Graphic;

namespace XTowerDef
{
    public class CreepParticle : ParticleBase
    {
        #region Fields Region
        private ParticleEngineBase parent;
        #endregion

        #region Property Region
        /// <summary>
        /// Get ParticleEngineBase which should manage this particle
        /// </summary>
        public ParticleEngineBase Parent
        {
            get { return parent; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor for a new Particle wich belongs to a creep.This is only a test 4 comparing the way of working with and without a base class
        /// </summary>
        /// <param name="pTexture">Particle Sprite Graphic</param>
        /// <param name="pPosition">Position</param>
        /// <param name="pVelocity">Particle Speed</param>
        /// <param name="pAngle">Rotation angle</param>
        /// <param name="pAngularVelocity">Changing speed of angle</param>
        /// <param name="pColor">Color</param>
        /// <param name="pSize">Size</param>
        /// <param name="pTtl">Time to life</param>
        public CreepParticle(Texture2D pTexture, ParticleEngineBase pParent, Vector2 pVelocity, float pAngle, float pAngularVelocity, Color pColor, float pSize, int pTtl)
            : base(pTexture, pParent.EmitterLocation, pVelocity, pAngle, pAngularVelocity, pColor, pSize, pTtl)
        {
            parent = pParent;
        }

        #endregion

        #region Abstract Method Region
        /// <summary>
        /// Do Logic for Particles
        /// </summary>
        public override void Update(GameTime pGameTime)
        {
            
            TTL--;
            Position += Velocity;
            Angle += AngularVelocity;
        }

        /// <summary>
        /// Do drawings for Particles
        /// </summary>
        /// <param name="pSpriteBatch">The graphic to draw</param>
        /// <param name="pLocation">The location where it's have to draw</param>
        public override void Draw(SpriteBatch pSpriteBatch)
        {
            Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
            Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            pSpriteBatch.Begin();
            pSpriteBatch.Draw(Texture, Position, sourceRectangle, Color,
                Angle, origin, Size, SpriteEffects.None, 0f);
            pSpriteBatch.End();

        }

        #endregion
    }
}
